package com.xgc.oauth.exception;


import com.xgc.oauth.dto.ResultDTO;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * 全局异常处理程序
 *
 * @author xgc
 * @date 2024/01/24
 */
@Slf4j
@RestController
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultDTO processDefaultException(Exception e) {
        return ResultDTO.fail(e.getMessage());
    }

    @ExceptionHandler(BizException.class)
    @ResponseBody
    public ResultDTO processUnifiedException(BizException e) {
        return ResultDTO.fail(e.getMsg());
    }
}
